package com.jzo2o.customer.controller.consumer;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 地址薄 前端控制器
 * </p>
 *
 * @author whx
 * @since 2024-12-02
 */
@RestController
@RequestMapping("/consumer/address-book")
@Api(tags = "地址簿相关接口")
public class AddressBookController {

    @Autowired
    private IAddressBookService addressBookService;

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public PageResult<AddressBook> page(AddressBookPageQueryReqDTO dto){
        return addressBookService.page(dto);
    }

    @PostMapping
    @ApiOperation("新增地址簿")
    public void addAddressBook(@RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.addAddressBook(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("查看地址簿详情")
    public AddressBook getById(@PathVariable Long id){
        return addressBookService.getById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("地址簿修改")
    public void updateById(@PathVariable Long id, @RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.updateById(id, dto);
    }

    @DeleteMapping("/batch")
    @ApiOperation("地址簿批量删除")
    public void deleteById(@RequestBody String ids){
        addressBookService.batchDelete(ids);
    }

    @PutMapping("/default")
    @ApiOperation("设置/取消默认地址")
    public void onOffDefault(Integer flag, Long id){
        addressBookService.onOffDefault(flag, id);
    }

    @GetMapping("/defaultAddress")
    @ApiOperation("获取默认地址")
    public AddressBook getDefault(){
        return addressBookService.getDefault();
    }

}
